home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb / dist / remote-multi.shar / remote_server.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-20  |  3.9 KB  |  138 lines

  1. /* Main code for remote server for GDB, the GNU Debugger.
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. GDB is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GDB is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GDB; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "param.h"
  21. #include <stdio.h>
  22.  
  23. void read_inferior_memory(), fetch_inferior_registers(); 
  24. unsigned char resume(); 
  25. void kill_inferior(); 
  26. void initialize(), try_writing_regs_command();  
  27. int create_inferior(), read_register(); 
  28.  
  29. extern char registers[]; 
  30. int inferior_pid; 
  31. extern char **environ; 
  32.  
  33. /* Descriptor for I/O to remote machine.  */
  34. int remote_desc;
  35. int kiodebug = 0;
  36. int remote_debugging; 
  37.  
  38. void remote_send ();
  39. void putpkt ();
  40. void getpkt ();
  41. void remote_open(); 
  42. void write_ok(); 
  43. void write_enn(); 
  44. void convert_ascii_to_int(); 
  45. void convert_int_to_ascii(); 
  46. void prepare_resume_reply(); 
  47. void decode_m_packet(); 
  48. void decode_M_packet(); 
  49.  
  50.  
  51. main(argc,argv)
  52. int argc; char *argv[]; 
  53. {
  54.     char ch,status, own_buf[2000], mem_buf[2000]; 
  55.     int i=0;  
  56.     unsigned char signal;  
  57.     unsigned int mem_addr, len; 
  58.  
  59.     initialize(); 
  60.     printf("\nwill open serial link\n"); 
  61.     remote_open("/dev/ttya",0); 
  62.  
  63.     if(argc < 2) 
  64.     { 
  65.         printf("Enter name of program to be run with command line args\n"); 
  66.         gets(own_buf); 
  67.         inferior_pid = create_inferior(own_buf,environ); 
  68.         printf("\nProcess %s created; pid = %d\n",own_buf,inferior_pid);
  69.     } 
  70.     else 
  71.     { 
  72.         inferior_pid = create_inferior(argv[1],environ); 
  73.         printf("\nProcess %s created; pid = %d\n",argv[1],inferior_pid);
  74.     } 
  75.  
  76.     do {  
  77.         getpkt(own_buf); 
  78.         printf("\nPacket received is>:%s\n",own_buf); 
  79.         i = 0; 
  80.         ch = own_buf[i++]; 
  81.         switch (ch) { 
  82.             case 'h':    /**********This is only for tweaking the gdb+ program *******/ 
  83.                         signal = resume(1,0,&status);
  84.                         prepare_resume_reply(own_buf,status,signal); 
  85.                         break; 
  86.                         /*************end tweak*************************************/ 
  87.  
  88.             case 'g':    fetch_inferior_registers();         
  89.                         convert_int_to_ascii(registers,own_buf,REGISTER_BYTES); 
  90.                         break; 
  91.             case 'G':    convert_ascii_to_int(&own_buf[1],registers,REGISTER_BYTES);
  92.                         if(store_inferior_registers(-1)==0)  
  93.                             write_ok(own_buf); 
  94.                         else  
  95.                             write_enn(own_buf); 
  96.                         break; 
  97.             case 'm':    decode_m_packet(&own_buf[1],&mem_addr,&len); 
  98.                         read_inferior_memory(mem_addr,mem_buf,len);
  99.                         convert_int_to_ascii(mem_buf,own_buf,len); 
  100.                         break; 
  101.             case 'M':    decode_M_packet(&own_buf[1],&mem_addr,&len,mem_buf); 
  102.                         if(write_inferior_memory(mem_addr,mem_buf,len)==0)  
  103.                             write_ok(own_buf); 
  104.                         else 
  105.                             write_enn(own_buf); 
  106.                         break; 
  107.             case 'c':    signal = resume(0,0,&status);
  108.                         printf("\nSignal received is >: %0x \n",signal); 
  109.                         prepare_resume_reply(own_buf,status,signal); 
  110.                         break; 
  111.             case 's':    signal = resume(1,0,&status);
  112.                         prepare_resume_reply(own_buf,status,signal); 
  113.                         break; 
  114.             case 'k':    kill_inferior();
  115.                         sprintf(own_buf,"q"); 
  116.                         putpkt(own_buf); 
  117.                         printf("\nObtained kill request...terminating\n"); 
  118.                          close(remote_desc); 
  119.                         exit(0); 
  120.             case 't':    try_writing_regs_command();
  121.                         own_buf[0] = '\0'; 
  122.                         break; 
  123.             default :    printf("\nUnknown option chosen by master\n"); 
  124.                         write_enn(own_buf); 
  125.                         break; 
  126.            } 
  127.  
  128.         putpkt(own_buf); 
  129.      }  while(1) ; 
  130.  
  131.     close(remote_desc); 
  132.     /** now get out of here**/ 
  133.     printf("\nFinished reading data from serial link - Bye!\n"); 
  134.     exit(0);
  135.  
  136. }
  137.  
  138.